<%@page language="java" import="com.scalar.chiptrack.users.Functionality,
                                com.scalar.chiptrack.users.User,
                                com.scalar.chiptrack.finance.purchaseorder.ReceivingsTransactionLineItem" %>

<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/struts-nested.tld" prefix="nested" %>
<%@ taglib uri="/WEB-INF/chiptrack-tags.tld" prefix="chiptrack" %>

<%@ page import="com.scalar.chiptrack.utils.ConfigManager"%>

<% int i = 0; %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html:html>
<HEAD><TITLE>Scalarsoft - ChipTrac</TITLE>

<%String chipTracContext = "/" + ConfigManager.getChipTracContext();%>

<chiptrack:checkLogon sourcePage="/jsp/finance/purchasing_lot_number_entry.jsp"/>
<%
    int receiptIndex =  -1;
    if( request.getParameter( "receiptIndex" ) != null )
    {
        try {
            receiptIndex = Integer.parseInt( request.getParameter( "receiptIndex" ).trim());
        } catch (NumberFormatException nfe ){
        }
    }
%>
<SCRIPT language="JavaScript" src="<%=chipTracContext%>/jsp/includes/scripts/validations.js">
</SCRIPT>
<script language="javascript">

function onLoading()
{
    var form = document.receivingsTransactionForm;
    var form = document.receivingsTransactionForm;
    var receiptIndex = form.receiptIndex.value - 1;

    form['receivingsTransaction.receivingsTransactionLineItemList['+receiptIndex+'].quantityShipped'].value =
    parseDec( form['receivingsTransaction.receivingsTransactionLineItemList['+receiptIndex+'].quantityShipped'].value, 0, '.' );
    calculateRemainingToSelect();
}

function calculateRemainingToSelect()
{
    var form = document.receivingsTransactionForm;
    var receiptIndex = form.receiptIndex.value - 1;
    var shipedQty = form['receivingsTransaction.receivingsTransactionLineItemList['+receiptIndex+'].quantityShipped'].value;
    var count = form.count.value;
    var remainingToSelect = 0;
    for( var i=0;i< count; i++ )
    {
      remainingToSelect = remainingToSelect + eval(form['receivingsTransaction.receivingsTransactionLineItemList['+receiptIndex+'].purchasingLotNumberEntryList['+i+'].qtyTaken'].value);
    }
    form.remainingToSelect.value = shipedQty - remainingToSelect;
}

function validateTotal()
{
    var form = document.receivingsTransactionForm;
    var receiptIndex = form.receiptIndex.value - 1;
    var shipedQty = form['receivingsTransaction.receivingsTransactionLineItemList['+receiptIndex+'].quantityShipped'].value;
    var count = form.count.value;
    var remainingToSelect = 0;
    for( var i=0;i< count; i++ )
    {
      remainingToSelect = remainingToSelect + eval(form['receivingsTransaction.receivingsTransactionLineItemList['+receiptIndex+'].purchasingLotNumberEntryList['+i+'].qtyTaken'].value);
    }
    form.remainingToSelect.value = shipedQty - remainingToSelect;
}

function reset()
{
    document.receivingsTransactionForm.reset();
}

function cancel()
{
    window.close();
}

function submit()
{
    var form = document.receivingsTransactionForm;
    document.receivingsTransactionForm.action.value='savePurchasingLotNumberEntry';
    document.receivingsTransactionForm.submit();
}

/*
function addMore()
{
    var form = document.receivingsTransactionForm;
    var errors = document.getElementById("errors");

    if ( form.remainingToSelect.value == 0 )
    {
        errors.innerHTML = " <li> The maximum number of lot numbers has been entered.";
    }
    else
    {
        document.receivingsTransactionForm.action.value='addPurchasingLotNumberEntry';
        document.receivingsTransactionForm.submit();
    }
}
*/
</script>

<META http-equiv='Content-Type' content='text/html; charset=windows-1252'>
<LINK href='<%=chipTracContext%>/jsp/includes/stylesheets/scalarsoft.css' type='text/css' rel='stylesheet'>

</HEAD>
<BODY bgColor='#ffffff' leftMargin='0' topMargin='0' marginheight='0' marginwidth='0' onLoad="javaScript:onLoading();">
<P>

<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
<TBODY>
<TR>
        <TD width='180' valign='top' background='<%=chipTracContext%>/jsp/includes/images/left_red_bg.gif'>
        <TD bgcolor="#ffffff">
            <IMG height=9 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=8></TD>
        <TD bgcolor="#ffffff"><IMG height=480 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=2></TD>
        <TD valign="top" width="100%">

<!-- SiteMap Tag -->
<chiptrack:sitemap styleClass="NArialS"/>

<chiptrack:permission functionality='<%=Functionality.RECEIVINGS_TRANSACTION %>'
    action='<%=User.USER_ACTION_MODIFY%>' styleClass="NArialL" >
</chiptrack:permission>

<IMG height=1 src="<%=chipTracContext%>/jsp/includes/images/clear.gif" width=500 border=0>
<BR>
<!-- from here your body starts -->
        <P>
            <TABLE BORDER="0" WIDTH="100%">
            <TR>
			    <TD WIDTH="100%">
                    <html:form name="receivingsTransactionForm" action="/autoReceivingAndInvoice.do" method="post" scope="session" type="com.scalar.chiptrack.finance.purchaseorder.forms.ReceivingsTransactionForm">
                    <TABLE BORDER="0" WIDTH="100%" HEIGHT="175%">
				    <TR>
					    <TD WIDTH="100%">
						    <TABLE BORDER="0" WIDTH="100%">
							<TR>
								<TD WIDTH="100%" class="NArialW">
									<P ALIGN="CENTER">Purchasing Lot Number Entry
								</TD>
							</TR>
                            <TR>
                               <TD WIDTH="100%">&nbsp;</TD>
                            </TR>
                            <TR>
                               <TD><chiptrack:info styleClass="NArialL" /></TD>
                            </TR>
                            <TR>
                               <TD><chiptrack:errors styleClass="NArialL" /></TD>
                            </TR>
                            <TR>
                               <TD><chiptrack:moreErrorInfo styleClass="NArialL" /></TD>
                            </TR>
						    </TABLE>
                            <BR>
						    <BR>
    					</TD>
                    </TR>
                    </TABLE>
                    <input type="hidden" name="receiptIndex" value="<%= receiptIndex %>" />
                    <input type= "hidden" name = "action" value="">
                    <nested:nest property="receivingsTransaction">
                        <nested:hidden property="receiptNumber" />
                        <nested:iterate id = "receivingsTransactionLineItem" property="receivingsTransactionLineItemList" type="com.scalar.chiptrack.finance.purchaseorder.ReceivingsTransactionLineItem">

                         <logic:equal name = "receivingsTransactionLineItem" property = "receiptIndex"  value = "<%= String.valueOf(receiptIndex)%>" >
                         <nested:hidden property="receiptNumber" />
                         <nested:hidden property="receivingsTransactionLineItemSequenceNo"/>
                         <input type="hidden" name="receiptsLineItemIndex" value="<%= receiptIndex %>"/>
                    <TABLE BORDER="0" WIDTH="90%" CLASS="NArialL">
                        <TR>
                            <TD width="100%">
                                <TABLE BORDER="0" WIDTH="100%">
                                    <TR>
                                        <TD width="50%">&nbsp;</TD>
                                        <TD width="25%" class='NArialL' align="right">Extended Quantity:</TD>
                                        <TD width="25%" align="right"><nested:text property="quantityShipped" styleClass="valuetxfield" size="10" disabled="true"/></TD>
                                    </TR>
                                    <TR>
                                        <TD width="50%">&nbsp;</TD>
                                        <TD class='NArialL' width="25%" align="right">Remaining to Select:</TD>
                                        <TD width="25%" align="right"><input type="text" name="remainingToSelect" class="valuetxfield" size="10" disabled="true"/></TD>
                                    </TR>
                                </TABLE>
                            </TD>
                        </TR>
                        <TR><TD>&nbsp;</TD></TR>
                        <TR>
                            <TD width="100%">
                                <TABLE BORDER="0" WIDTH="80%" align="right" CLASS="NArialL">
                                    <TR>
                                    <TD COLSPAN="2" CLASS="NArialL"><FONT id="errors" styleClass="NArialL" color="red"></FONT></TD>
                                    <TR>
                                    <TR>
                                        <TD width="70%" HEIGHT="26" ALIGN="CENTER" BGCOLOR="#993333"><P ALIGN="CENTER">&nbsp;<FONT COLOR="white">Lot Numbers Selected</FONT>
                                        </TD>
                                        <TD width="30%"  HEIGHT="26" ALIGN="CENTER" BGCOLOR="#993333"><P ALIGN="CENTER">&nbsp;<FONT COLOR="white">Quantity Selected</FONT></TD>
                                    </TR>
                                    <nested:iterate id = "purchasingLotNumberEntry" property="purchasingLotNumberEntryList" type="com.scalar.chiptrack.finance.purchaseorder.PurchasingLotNumberEntry">

                                    <TR>
                                    <TD ALIGN="CENTER" BGCOLOR="#DEE1E2">
                                            <P><nested:text property="lotNumber" styleClass="txfield" size="19"  disabled="true"/>
                                    </TD>
                                    <TD ALIGN="CENTER" BGCOLOR="#DEE1E2" nowrap>
                                            <P><nested:text property="qtyTaken" onblur="javascript:validateTotal();" styleClass="txfield" size="9"  disabled="true"/>
                                    </TD>
                                    </TR>
                                    <% i++;%>
                                    </nested:iterate>
                                </TABLE>
                            </TD>
                        </TR>
                    </TABLE>

                         </logic:equal>

                        </nested:iterate>

                    </nested:nest>
                    <input type= "hidden" name = "count" value="<%=i%>">


                    <TABLE BORDER="0" WIDTH="100%">
                    <TR><TD colspan="4">&nbsp;</TD></TR>
                    <TR>
                        <TD WIDTH="40%">&nbsp;</TD>
                        <TD WIDTH="10%" align="center"><!--
                            <A href="javascript:submit()" onmouseover="window.status='Click here to Save Purchasing Lot Number Entry Details';return true" onmouseout="window.status='';return true"><IMG SRC="<%=chipTracContext%>/jsp/includes/images/save.gif" ALIGN="BOTTOM" BORDER="0"></A>-->
                        </TD>
                        <TD WIDTH="20%">
                            <A href="javascript:cancel()" onmouseover="window.status='Click here to Close this window';return true" onmouseout="window.status='';return true">
                            <IMG SRC="<%=chipTracContext%>/jsp/includes/images/cancel.gif" ALIGN="BOTTOM" BORDER="0"></A>
                        </TD>
                        <TD WIDTH="30%">&nbsp;</TD>
                    </TR>
                    <TR><TD colspan="4">&nbsp;</TD></TR>
                    </TABLE>


                    </html:form>
                </TD>
            </TR>
			</TABLE>
<!-- Your Work area ends here -->
		</TD>
		<TD BGCOLOR="white"><IMG SRC="images/spacer.gif" WIDTH="1" HEIGHT="1" ALIGN="BOTTOM" BORDER="0"></TD>
	</TR>
</TBODY>
</TABLE>

</BODY>
</html:html>
